///////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2010 Chris Colinsky
// All Rights Reserved
//
// version	0.5
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

package sugarcookie.events {
	import flash.events.Event;
	
	import mx.logging.Log;
	import mx.logging.ILogger;
	import mx.utils.ObjectUtil;
	
	import sugarcookie.utils.StringUtil;

	/**
	 * Extends the Event class to enable data to be sent with events, be have the option of auto-logging and a simple status boolean.
	 */
	public class GenericEvent extends Event {
		public static var READY:String = "ready";
		public static var COMPLETE:String = "complete";
		public static var DEACTIVATE:String = "deactivate";
		
		public static var LOG_DATA:Boolean = true;
		
		public var status:Object;
		public var isLogable:Boolean;
		public var data:Object;
		
		private var _log:ILogger;
		
		public function GenericEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false, _status:Object=null, _isLogable:Boolean=false, _data:Object=null) {
			super(type, bubbles, cancelable);
			status = _status;
			isLogable = _isLogable;
			data = _data;
			
			if (_isLogable) {
				initLogger();
				postLogMsg();
			}
		}
		
		protected function initLogger():void {
			_log = Log.getLogger(StringUtil.getFormattedClassName(this));
		}
		
		protected function postLogMsg():void {
			_log.debug(toString());
			if (GenericEvent.LOG_DATA) _log.debug("Event Data: "+ObjectUtil.toString(data));
			
		}
		
		override public function clone():Event{
			return new GenericEvent(type, bubbles, cancelable, status, isLogable, data);
		}
		
		override public function toString():String {
			return formatToString("GenericEvent", "type", "bubbles", "cancelable", "eventPhase", "status", "isLogable", "data");
		}
	}
}